// this function is used to MasterData
function autoInputMasterData(inElement) {
	inElement.autocomplete({
		source : function(request, response) {
			var category = inElement.attr("category");
			$.ajax({
				url : "masterdata/list" + category + "/" + inElement.val(),
				data : null,
				type : "POST",
				success : function(data) {

				}
			});

			DWRActionUtil.execute({
				namespace : "/coagclinic",
				action : "autoComplete",
				executeResult : 'true'
			}, {
				expression : "%" + request.term + "%",
				'category' : this.element[0].getAttribute("category"),
				'parent' : parent
			}, function(data) {
				eval(data);
				response(sourceList);
			});
		},
		autoSelect : true,
		focus : function(event, ui) {
			// $( this ).val( ui.item.label );
			return false;
		},
		select : function(event, ui) {
			if (event.keyCode == 9)
				return false;
			$(this).val(ui.item.label);
			$(this).nextAll("input:first").val(ui.item.value);
			return false;
		}
	});

	inElement.on('input', function(e) {
		var val = $(this).val();
		if (!val || val == "") {
			$(this).nextAll("input:first").val("");
		}
	});
}

function autoCompleteInput(element) {
	element.autocomplete({
				source : function(query, process) {
					var category = element.attr("category");
					var matchCount = this.options.items;// 返回结果集最大数量
					
					$.post("/masterdata/list/" + category + "/" + element.val(), {}, function(respData) {
//						console.log(respData);
						return process(respData.masterData);
					});
				},
				formatItem : function(item) {
					return item["value"];
				},
				setValue : function(item) {
//					$(this).nextAll("input:first").val(item["id"]);
					return {
						'data-value' : item["value"],
						'real-value' : item["id"]
					};
				}
	});
	
}

function autoCompleteInput(element,callback) {
	element.autocomplete({
		source : function(query, process) {
			var category = element.attr("category");
			var matchCount = this.options.items;// 返回结果集最大数量
			
			$.post("/masterdata/list/" + category + "/" + element.val(), {}, function(respData) {
//				console.log(respData);
				return process(respData.masterData);
			});
		},
		formatItem : function(item) {
			return item["value"];
		},
		setValue : function(item) {
//			$(this).nextAll("input:first").val(item["id"]);
		
			return {
				'data-value' : item["value"],
				'real-value' : item["id"]
			};
		},
		selectCallback: function(val){
			if(callback)
			callback(val);
		}
});

}